package com.diyunapp.xilinapp.bean;

import com.diyunapp.xilinapp.utils.FormatConfirm;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by NIDAYE on 2016/6/15.
 */
public class BuyCarGoodsOutBean {

    private String storeId;
    private String buyerId;
    private List<BuyCarGoodsInBean> goodsList;
    private String storeName;
    private int totalGoodsNum;
    private float totalGoodsPrice;
    private boolean isStoreSelected; //是否选中了商店

    public boolean onlyUI;

    public BuyCarGoodsOutBean(String storeId, String buyerId,String storeName,  boolean isStoreSelected) {
        this.storeId = storeId;
        this.buyerId = buyerId;
        this.storeName = storeName;
        this.isStoreSelected = isStoreSelected;
        this.totalGoodsNum = 0;
        this.totalGoodsPrice = 0;
        this.onlyUI = false;
        goodsList = new ArrayList<>();
    }

    public String getStoreId() {
        return storeId;
    }

    public void setStoreId(String storeId) {
        this.storeId = storeId;
    }

    public String getBuyerId() {
        return buyerId;
    }

    public void setBuyerId(String buyerId) {
        this.buyerId = buyerId;
    }

    public List<BuyCarGoodsInBean> getGoodsList() {
        return goodsList;
    }

    public void setGoodsList(List<BuyCarGoodsInBean> goodsList) {
        this.goodsList = goodsList;
    }

    public String getStoreName() {
        return storeName;
    }

    public void setStoreName(String storeName) {
        this.storeName = storeName;
    }

    public boolean isStoreSelected() {
        return isStoreSelected;
    }

    public void setStoreSelected(boolean storeSelected) {
        isStoreSelected = storeSelected;
    }

    public void setAllGoodsState(boolean select)
    {
        for(int i=0;i<goodsList.size();i++)
        {
            getGoodsList().get(i).setGoodSelected(select);
        }
    }

    public float getTotalPrice()
    {
        totalGoodsPrice = 0;
        for(int i=0;i<goodsList.size();i++)
        {
            if(goodsList.get(i).isGoodSelected())
            {
                float price = FormatConfirm.stringToFloat(goodsList.get(i).getGoodPrice());
                totalGoodsPrice += price*goodsList.get(i).getTotalGoodNum();
            }

        }
        return  totalGoodsPrice;
    }

    public float getTotalOutPrice()
    {
        totalGoodsPrice = 0;
        for(int i=0;i<goodsList.size();i++)
        {
            float price = FormatConfirm.stringToFloat(goodsList.get(i).getGoodPrice());
            totalGoodsPrice += price*goodsList.get(i).getTotalGoodNum();
        }
        return  totalGoodsPrice;
    }

    public int getTotalNum()
    {
        totalGoodsNum = 0;
        for(int i=0;i<goodsList.size();i++)
        {
            if(goodsList.get(i).isGoodSelected())
            {
                totalGoodsNum += goodsList.get(i).getTotalGoodNum();
            }
        }

        return  totalGoodsNum;
    }

    public boolean ifAllGoodsSeleted()
    {
        boolean flag = true;
        for(int i=0;i<goodsList.size();i++)
        {
            if(!goodsList.get(i).isGoodSelected())
            {
                flag = false;
                break;
            }
        }
        return flag;
    }
}
